﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            //FundID, FundName, FundContent, RunPeople, CreateTime, Remark
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'ID', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '基金简称', name: 'FundName', width: "15%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '状态', name: 'Status', width: "5%", sortable: true, hide: true, align: 'left', iskey: true,process:staOP },
                    { display: '私募公司', name: 'FundCompany', width: "15%", sortable: false, align: 'left'},
                    //{ display: '内容', name: 'FundContent', width: "15%", sortable: false, align: 'left' },
                    //{ display: '负责人', name: 'RunPeople', width: "12%", sortable: false, align: 'left' },
                    //{ display: '注册资金', name: 'RegistedCapital', width: "8%", sortable: false, align: 'left' },
                    { display: '创立时间', name: 'CreateTime', width: "12%", sortable: false, align: 'left' },
                    { display: '操作', name: 'ID', width: "15%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "ID",
            sortorder: "ASC",
            title: false,
            rp: 10,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            if (cell[2] == 0) {
                ops.push("&nbsp;<a title='查看' href='javascript:;'  onclick=\"util.See('", value, "')\"><i class='fa fa-edit' ></i>查看</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            }
            else if (cell[2] == 1 || cell[2]==2) {
                ops.push("&nbsp;<a title='查看' href='javascript:;'  onclick=\"util.See('", value, "')\"><i class='fa fa-edit' ></i>查看</a>");
                ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            }
            return ops.join("");
        }   
        function staOP(value,cell){
            if (value==0) {
                return '正常';
            } else if(value==1) {
                return '不正常';
            }
        }
        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            //parent.location.href = url;
            window.location.href = url;
        });
        
        util.See = function (ID) {
            var url = options.showUrl + "/" + ID;
            location.href = url;
        };
        util.Edit = function (ID) {
            var url = options.editUrl + "/" + ID;
            location.href = url;
        };
        util.Delete = function (ID, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + ID, { ID: ID },
                  function (res) {
                      if (res.status > 0) {
                          alert(res.message);
                          xjgrid.Reload(this);
                      }
                      else {
                          alert(res.Message);
                      }
                  },
                  "json"
            );
        };
    });
})(window, undefined, jQuery);